package com.itheima.mapper;

import com.itheima.pojo.Comment;
import com.itheima.pojo.SubComment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Select("select * from comment where article_id = #{articleId} order by create_time desc limit 100")
    List<Comment> getCommentList(Integer articleId);

    @Insert("insert into comment(content,create_user,create_time,article_id) values(#{content},#{createUser},now(),#{articleId})")
    void addComment(Comment comment);

    @Select("select * from subcomment order by create_time desc")
    List<SubComment> getSubCommentList();

    @Insert("insert into subcomment(father_id,content,create_user,create_time) values(#{fatherId},#{content},#{createUser},now()) ")
    void addSub(SubComment subComment);

    List<Comment> manageComment(String content, Integer userId);

    @Delete("delete from comment where id = #{id}")
    void deleteComment(Integer id);

    List<SubComment> manageSubComment(String content, Integer userId);

    @Delete("delete from subcomment where id = #{id}")
    void deleteSubComment(Integer id);
}
